/**
 * @author lxxxvi / https://github.com/lxxxvi
 * Developed as part of a project at University of Applied Sciences and Arts Northwestern Switzerland (www.fhnw.ch)
 */

module( "SetMaterialMapCommand" );

test( "Test for SetMaterialMapCommand (Undo and Redo)", function() {

	// setup
	var editor = new Editor();
	var box = aBox( 'Material mapped box' );
	var cmd = new AddObjectCommand( box );
	cmd.updatable = false;
	editor.execute( cmd );

	var mapNames = [ 'map', 'alphaMap', 'bumpMap', 'normalMap', 'displacementMap', 'specularMap', 'envMap', 'lightMap', 'aoMap' ];

	// define files
	var dirt  = { name: 'dirt.png' , data: '' };
	var stone = { name: 'stone.png', data: '' };
	var files = [ dirt, stone ];

	// define images for given files
	var images = files.map( function( file ) {

		var i = new Image();
		i.src = file.data;
		return { name: file.name, image: i };

	} );


	// test all maps
	mapNames.map( function( mapName ) {


		// define textures for given images
		var textures = images.map( function( img ) {

			var texture = new THREE.Texture( img.image, mapName );
			texture.sourceFile = img.name;
			return texture;

		} );

		// apply the textures
		textures.map( function( texture ) {

			var cmd = new SetMaterialMapCommand( box, mapName, texture );
			cmd.updatable = false;
			editor.execute( cmd );

		} );


		ok( box.material[ mapName ].image.src == images[ images.length - 1 ].image.src,
			"OK, " + mapName + " set correctly " );

		editor.undo();
		ok( box.material[ mapName ].image.src == images[ images.length - 2 ].image.src,
			"OK, " + mapName + " set correctly after undo " );

		editor.redo();
		ok( box.material[ mapName ].image.src == images[ images.length - 1 ].image.src,
			"OK, " + mapName + " set correctly after redo" );

	} );

} );
